﻿#region Header
// ------------------------ Licence / Copyright ------------------------
// 
// ScrumTable for Scrum Meeting Support
// Copyright © HSR - Hochschule für Technik Rapperswil
// All Rights Reserved
// 
// Author:
//  Michael Gfeller Silvan Gehrig Patrick Boos
// 
// ---------------------------------------------------------------------
#endregion

#region Usings

using System.Collections.Generic;
using System.Linq;
using System.Xml.Serialization;

#endregion

namespace ScrumTable.DL.Data.Common.Serialization
{
    /// <summary>
    /// Contains the properties and child elements of the DataObject
    /// element. This class is needed for serialization purposes.
    /// </summary>
    [XmlRoot("DataObject")]
    public class DataObject
    {
        #region Declarations
        //--------------------------------------------------------------------
        // Declarations
        //--------------------------------------------------------------------

        #endregion

        #region Properties
        //--------------------------------------------------------------------
        // Properties
        //--------------------------------------------------------------------
        
        /// <summary>
        /// Specifies the Id attribute.
        /// </summary>
        [XmlAttribute("Id")]
        public string Id { get; set; }

        /// <summary>
        /// Specifies the OrderIndex attribute.
        /// </summary>
        [XmlAttribute("OrderIndex")]
        public double OrderIndex { get; set; }
        
        /// <summary>
        /// Specifies the ParentIds attribute.
        /// </summary>
        [XmlAttribute("ParentIds")]
        public string ParentIds { get; set; }

        /// <summary>
        /// Gets a list of serialized/deserialized DataValue instances.
        /// </summary>
        [XmlElement("DataValue")]
        public List<DataValue> DataValues
        {
            get;
            set;
        }

        /// <summary>
        /// Gets the underlying object with the given schema name.
        /// </summary>
        /// <param name="name">Schema name of the underlying object to retreive.</param>
        /// <returns>Returns the retreived object.</returns>
        [XmlIgnore]
        public DataValue this[string name]
        {
            get
            {
                return (from dataValue in DataValues
                        where dataValue.Name == name
                        select dataValue).FirstOrDefault();
            }
        }

        #endregion

        #region Constructors / Destructor
        //--------------------------------------------------------------------
        // Constructors / Destructor
        //--------------------------------------------------------------------

        /// <summary>
        /// Public constructor needed for serialization facilities.
        /// </summary>
        public DataObject()
        {
            DataValues = new List<DataValue>();
        }

        #endregion

        #region Methods
        //--------------------------------------------------------------------
        // Methods
        //--------------------------------------------------------------------

        #endregion

        #region Events
        //--------------------------------------------------------------------
        // Events
        //--------------------------------------------------------------------

        #endregion
    }
}